<!DOCTYPE html>
<meta charset="utf-8">
<title>HTML Test: document base URL</title>
<link rel="author" title="Intel" href="http://www.intel.com/">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
  iframe { display: none }
</style>
<body onload="on_load()">
  <div id="log"></div>
  <script>
    var t1 = async_test("The document base URL of a document containing one or more base elements with href attributes is the frozen base URL of the first base element in the document that has an href attribute, in tree order.");

    function on_load() {
      t1.step(function () {
        var base = document.createElement("base");
        base.setAttribute("href", "/foo/bar");
        document.head.appendChild(base);
        assert_equals(document.baseURI, base.href, "The document base URL should be URL of the first base element that has an href attribute.");
      });
      t1.done();
    }

    async_test(function() {
      var iframe = document.createElement("iframe");
      iframe.onload = this.step_func_done(function () {
        assert_equals(iframe.contentDocument.baseURI, iframe.contentDocument.location.href, "The document base URL should be the document's address.");
      });
      iframe.setAttribute("src", "/common/blank.html");
      document.body.appendChild(iframe);
    }, "The fallback base URL of a document containing no base element is the document's address.");

    async_test(function () {
      var iframe = document.createElement("iframe");
      iframe.onload = this.step_func_done(function () {
        assert_equals(iframe.contentDocument.baseURI, document.baseURI, "The document base URL should be the creator document's base URL.");
      });
      iframe.setAttribute("src", "about:blank");
      document.body.appendChild(iframe);
    }, "The fallback base URL of a document whose address is about:blank is the document base URL of the creator document.");

    async_test(function () {
      var iframe = document.createElement("iframe");
      iframe.onload = this.step_func_done(function () {
        assert_equals(iframe.contentDocument.baseURI, document.baseURI, "The document base URL should be the containing document's base URL.");
      });
      iframe.setAttribute("srcdoc", "<p>foobar</p>");
      document.body.appendChild(iframe);
    }, "The fallback base URL of an iframe srcdoc document is the document base URL of the document's browsing context's browsing context container's document.");
  </script>
</body>
